<template>
	<view style="width: 750rpx;height: 100%;position: relative;display: flex;flex-direction: column;align-items: center;background: #FFFFFF;">
		<view v-if="list_" style="position: absolute;width: 618.5rpx;top:140rpx ;display: flex;flex-direction: column;align-items: center;">
			<view style="font-size: 33rpx;color: #373737;letter-spacing: 1rpx;">请绑定手机号</view>
			<view style="width: 618.5rpx;height: 78.51rpx;position: relative;margin-top: 49rpx;">
				<input v-model="login" placeholder="请输入手机号码" style="width: 618.5rpx;height: 78.51rpx;background: #F5F5F5;box-sizing: border-box;padding: 20.77rpx 32rpx;font-size: 30.2rpx;" />
			</view>
			<view style="width: 618.5rpx;height: 78.51rpx;position: relative;margin-top: 49rpx;">
				<input v-model="yanzheng" placeholder="验证码" style="width: 618.5rpx;height: 78.51rpx;background: #F5F5F5;box-sizing: border-box;padding: 20.77rpx 32rpx;font-size: 30.2rpx;"/>
				<view @tap="asa" style="position: absolute;color: #EE7B30;font-size: 26.58rpx;top: 26rpx;left: 447rpx;height:26.58rpx ;z-index: 1212121;width: 138rpx;text-align: center;" >{{text}}</view>
			</view>
			<view @tap="denglu" style="width: 618.5rpx;height: 78.51rpx;background: #EE7B30;text-align: center;line-height: 78.51rpx;font-size: 33.83rpx;color: #FFFFFF;font-weight: bold;letter-spacing: 3rpx;margin-top: 87rpx;border-radius: 6rpx;">提交</view>
		</view>
		<view style="position: absolute;width: 137.11rpx;top: 203rpx;left: 306.82rpx;text-align: center;" v-if="!list_">
			<view>
				<image src="../../../static/newshouye/denglu_jiao.png" style="width: 137.11rpx;height: 137.11rpx;"></image>
			</view>
			<view style="color: #EE7B30;font-size: 41.676rpx;font-weight: bold;margin-top: 50.13rpx;">
				教付保
			</view>
		</view>
		<view style="position: absolute;width: 750rpx;box-sizing: border-box;top: 683.124rpx;display: flex;flex-direction: column;align-items: center;" v-if="!list_">
			<view style="width: 648.69rpx;">
				<button  open-type="getUserInfo" lang="zh_CN" @getuserinfo="appLoginWx" style="background: #EE7B30;font-size: 29rpx;border-radius: 42.89rpx;text-align: center;line-height: 85.76rpx;height: 85.76rpx;width: 648.69rpx;display: flex;justify-content: center;align-items: center;color: #FFFFFF;">微信登录</button>
			</view>
			<view style="width: 270rpx;display: flex;align-items: center;margin-top: 50rpx;" @tap.stop="goshu">
				<text style="font-size: 29rpx;color: #EE7B30;width: 240rpx;">手机号登录 / 注册</text>
				<image src="../../../static/newshouye/jian_.png" style="width: 16.3rpx;height: 22.96rpx;vertical-align: middle;width:16.3rpx ;"></image>
			</view>
		</view>
		<view style="font-size: 21.744rpx;color: #424242;position:fixed;bottom: 62rpx;">
			<text>登录代表您已同意</text>
			<text style="color: #EE7B30;">《教付保用户协议》</text>
			<text>和</text>
			<text style="color: #EE7B30;">《教付保隐私协议》</text>
		</view>
	</view>
</template>
<script>
	export default {
		data(){
			return {
				login:"",
				yanzheng:"",
				list:false,
				list_:false,
				user_list:{},
				text:"获取验证码"
			}
		},
		methods:{
			settime(){
				let me = this
				let time = 60
				const res = setInterval(() => {
					if(time > 0){
						time--
						me.text = time + "s"
					}else{
						clearInterval(res)
						me.text = "获取验证码"
					}
				},1000)
			},
			asa(){
				let me = this
				uni.request({
					url:"https://www.curiousmore.com/qmore/user/sms/send",
					method:"get",
					data:{
						type:'login',
						mobile: me.login
					},
					header:{
						'content-type':'application/json'
					},
					success:(res) => {
						if(res.data.code == 0){
							uni.showToast({
								title:"手机验证码发送成功"
							})
							me.settime()
							try{
								me.user_list = uni.getStorageSync('userinfo_')
							}catch(e){}
						}
 					}
				})
			},
			denglu(){
				let me = this
				if(me.yanzheng){
					uni.request({
						url:"https://www.curiousmore.com/qmore/user/user/login",
						method:"post",
						data:{
							login_name:me.login,
							verification_code:me.yanzheng,
							login_type:"2",
							platform:"wx",
							is_teach_paypal:"true"
						},
						header:{
							'content-type':'application/json'
						},
						success:(res) => {
							if(res.data.code == 0){
								uni.navigateTo({
									url: '/pages/tabBer/newsshouye/newsshouye'
								})
								try {
									uni.setStorageSync('userif_list', res.data.data.userInfoEntity);
									uni.setStorageSync('user_token', res.data.data.userToken);
								} catch (e) {}
							}else{
								me.weixindenglu()
							}
						}
					})
				}else{
					uni.showToast({
						title:"验证码不能为空",
						icon:"none"
					})
				}
			},
			goshu(){
				uni.reLaunch({
					url:"/pages/tabBer/login/logins"
				})
			},
			weixindenglu(){
				let me = this
				uni.login({
					success:(res) => {
						uni.request({
							url:"https://www.curiousmore.com/qmore/user/user/openIdAppVerification",
							method:"POST",
							data:{
								platform:"wx",
								is_teach_paypal:"true",
								code:res.code
							},
							header:{
								'content-type':'application/json'
							},
							success:(res_) => {
								console.log(res_,"res_res_res_res_res_res_res_")
								try{
									let val = uni.getStorageSync('userinfo_')
								}catch(e){}
								uni.request({
									url:"https://www.curiousmore.com/qmore/user/user/openIdLoginOrRegist",
									method:"POST",
									data:{
										platform:"wx",
										is_teach_paypal:"true",
										wx_openid:res_.data.data.open_id,
										avatar:me.user_list.avatarUrl,
										nick_name:me.user_list.nickName,
										sex:me.user_list.gender
									},
									header:{
										"content-type":"application/json"
									},
									success:(re) => {
										if(re.data.code == 0){
											try {
												uni.setStorageSync('userif_list', re.data.data.userInfoEntity);
												uni.setStorageSync('user_token', re.data.data.userToken);
											} catch (e) {}
											setTimeout(() => {
												uni.navigateTo({
													url: '/pages/tabBer/newsshouye/newsshouye'
												})
											},1000)
										}
									}
								})
							}
						})
					}
				})
			},
			appLoginWx(){
				let me = this
				uni.getUserInfo({
					success:(res) => {
						try{
							uni.setStorageSync('userinfo_', res.userInfo)
						}catch(e){}
						me.list_ = true
					}
				})
			},
			appLoginWx_(){
				let me = this
				uni.getUserInfo({
					success:(re) => {
						uni.login({
							success:(res) => {
								uni.request({
									url:"https://www.curiousmore.com/qmore/user/user/openIdAppVerification",
									method:"post",
									data:{
										platform:"wx",
										is_teach_paypal:"true",
										code:res.code
									},
									header:{
										"content-type":"application/json"
									},
									success:(res_) => {
										uni.request({
											url:"https://www.curiousmore.com/qmore/user/user/openIdLoginOrRegist",
											method:"POST",
											data:{
												platform:"wx",
												is_teach_paypal:"true",
												wx_openid:res_.data.data.open_id,
												avatar:re.userInfo.avatarUrl,
												nick_name:re.userInfo.nickName,
												sex:re.userInfo.gender
											},
											header:{
												"content-type":"application/json"
											},
											success:(hell) => {
												if(hell.data.code == 0){
													try {
														uni.setStorageSync('userif_list', hell.data.data.userInfoEntity);
														uni.setStorageSync('user_token', hell.data.data.userToken);
													} catch (e) {}
													setTimeout(() => {
														uni.navigateTo({
															url: '/pages/tabBer/newsshouye/newsshouye'
														})
													},1000)
												}
											},
											fail:(err) => {
												console.log(err)
											}
										})
									}
								})
							}
						})
					}
				})
			}
		},
		onLoad() {
			
		},
		onShow() {
			
		}
	}
</script>
<style lang="scss" scoped>
	.sys_btn{
		background: transparent;
		border: none;
		color:#FFFFFF ;
	}
</style>